home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 6826 / 6826.xpi / content / options.js < prev    next >
Text File  |  2008-03-27  |  3KB  |  147 lines

  1. //borrow  from flashblock
  2.  
  3. function checkSiteName(siteName) {
  4.     var regex = /^[A-Za-z0-9_\-\.\*]+(\:\d{1,5}){0,1}$/; 
  5.     return regex.test(siteName);
  6. }
  7.  
  8.  
  9. function compareSites(listSite,newSite)
  10. {
  11.     if(listSite<=newSite)
  12.     {
  13.         return false;
  14.     }
  15.     else
  16.     {
  17.         return true;
  18.     }
  19. }
  20.  
  21. function siteInList(site)
  22. {
  23.     var listRef=$("exceptionList");    
  24.     var listLen=listRef.getRowCount();
  25.     for(var i=0;i<listLen;i++)
  26.     {
  27.         if(listRef.getItemAtIndex(i).label == site)
  28.             return true;
  29.     }
  30.     return false;
  31. }
  32.  
  33. function getListIndex(site)
  34. {
  35.     var listRef=$("exceptionList");    
  36.     var listLen=listRef.getRowCount();
  37.     for(var i=0;i<listLen;i++)
  38.     {
  39.         if(compareSites(listRef.getItemAtIndex(i).label,site))return i; 
  40.     }
  41.     return i;
  42. }
  43.  
  44.  
  45.  
  46. function addExceptionSite()
  47. {
  48.     var val=$("siteTextbox").value;    
  49.     var listRef=$("exceptionList");
  50.     if(!checkSiteName(val))
  51.     {
  52.         alert("Invalid site name");
  53.         return false;
  54.     }
  55.     if(siteInList(val))
  56.     {
  57.         alert("Site is already in the list");
  58.         return false;
  59.     }
  60.     var index=getListIndex(val);
  61.     var numRows=listRef.getRowCount();
  62.     var newElement;
  63.     if(index < numRows)
  64.             newElement = listRef.insertItemAt(index, val, "");
  65.         else
  66.             newElement = listRef.appendItem(val, "");
  67.     listRef.ensureElementIsVisible(newElement);
  68.     var txb=$("siteTextbox");
  69.     txb.value="";
  70.     txb.focus();
  71.     $("onSiteTextBox").setAttribute("disabled",true);
  72.     return true;
  73. }
  74.  
  75.  
  76. function getExceptionsString()
  77. {
  78.     var list=$("exceptionList");
  79.     var listLen=list.getRowCount();
  80.     var listStr=new Array();
  81.     for(var i=0;i<listLen;i++)
  82.     {
  83.         listStr.push(list.getItemAtIndex(i).label);
  84.     }
  85.     return listStr.join(",");
  86. }
  87.  
  88. function setExceptionPref(listValue)
  89. {
  90.     gAdsRemoveUtils.setPreference("exception_list",getExceptionsString());
  91. }
  92.  
  93. function onInput(txref)
  94. {        
  95.     var cmdRef=$("onSiteTextBox");
  96.     if(txref.value)
  97.     {
  98.         cmdRef.setAttribute("disabled",false);
  99.     }
  100.     else
  101.     {
  102.         cmdRef.setAttribute("disabled",true);    
  103.     }
  104. }
  105.  
  106. function populateExceptionList()
  107. {
  108.     var prefExlist=gAdsRemoveUtils.getPreference("exception_list");
  109.     if(prefExlist=="")return;
  110.     var prefExlist=prefExlist.split(",");
  111.     var listRef=$("exceptionList");
  112.     for(var i=0;i<prefExlist.length;i++)
  113.     {
  114.         listRef.appendItem(prefExlist[i],"");
  115.     }
  116. }
  117.  
  118. function removeAllExceptions()
  119. {
  120.     var list=$("exceptionList");
  121.     while(list.getRowCount()>0)
  122.     {
  123.         list.removeItemAt(0);    
  124.     }
  125. }
  126.  
  127. function itemSelected(listitem)
  128. {
  129.     $("onRemoveSelected").setAttribute("disabled",false);
  130. }
  131. function removeSelectedItem()
  132. {
  133.     var list=$("exceptionList");    
  134.     var index=list.selectedItem;
  135.     index=list.getIndexOfItem(index);
  136.     list.removeItemAt(index);
  137.     $("onRemoveSelected").setAttribute("disabled",true);
  138. }
  139.  
  140. function saveBlockOptions()
  141. {
  142.     setExceptionPref(getExceptionsString());    
  143. }
  144.  
  145.  
  146.  
  147.